import request from '@/utils/request'
// 查询列表
export function queryTableData(query:any) {
  return request({
    url: '/timeAnalysis/continous/listAll',
    method: 'get',
    params: query,
    timeout: 600000  /* 2Min */
  })
}

// 级联查询父设备
export function getTopId(query:any) {
  return request({
    url: '/parameter/getMachineGroupByMachineTypeId',
    method: 'get',
    params: query
  })
}

// 级联查询子设备
export function getSon(query:any) {
  return request({
    url: 'interface/api/sonAll',
    method: 'get',
    params: query
  })
}

const cellRenderer = (params:any) => {
  return `<div style="background: ${params.data.color}; width: 80%; height: 70%; line-height: 20px; margin: 3px 6px;">${params.value}</div>`
}
const cellRendererPre = (params:any) => {
  return `<div style="background: ${params.data.preColor}; width: 80%; height: 70%; line-height: 20px; margin: 3px 6px;">${params.value}</div>`
}
const commonColumn = [
  // { headerName: "主线ID", field: "machineGroup", minWidth: 100, flex: 1 },
  { headerName: "父设备", field: "topId", width: 100, pinned: 'left' },
  { headerName: "设备ID", field: "machineId", width: 100, pinned: 'left' },
  // { headerName: "变更事件", field: "eventName", minWidth: 100, flex: 1 },
  // { headerName: "损失反应", field: "lossType", minWidth: 100, flex: 1 },
  { headerName: "开始时间", field: "createTime", minWidth: 150, flex: 1 },
  { headerName: "结束时间", field: "endTime", minWidth: 150, flex: 1 },
  { headerName: "持续时长/分", field: "keepTime", minWidth: 120, flex: 1 },
  { headerName: "反应时长/分", field: "reactTime", minWidth: 120, flex: 1 },
  { headerName: "前状态", field: "status", minWidth: 70, flex: 1, cellRenderer: cellRendererPre },
  { headerName: "现状态", field: "lastStatus", minWidth: 70, flex: 1, cellRenderer },
  { headerName: "RCode", field: "rcode", minWidth: 100, flex: 1 },
  { headerName: "Code描述", field: "codeDescription", minWidth: 100, flex: 1 },
  { headerName: "制造类型", field: "productType", minWidth: 100, flex: 1 },
  { headerName: "源设备ID", field: "sourceMachineId", minWidth: 100, flex: 1 },
  { headerName: "源设备类型", field: "sourceMachineType", minWidth: 100, flex: 1 },
  { headerName: "停机区分", field: "shutdownType", minWidth: 100, flex: 1 }

]

export const allColumn = [
  ...commonColumn,
  { headerName: "损失计件", field: "lossCount", minWidth: 100, flex: 1, filter: 'agMultiColumnFilter' },
  { headerName: "累计持续时长/分", field: "totalTime", minWidth: 120, flex: 1, filter: 'agMultiColumnFilter' },
  { headerName: "累计反映时长/分", field: "totalReactTime", minWidth: 120, flex: 1, filter: 'agMultiColumnFilter' },
  { headerName: "备注", field: "remark", minWidth: 400, flex: 1, tooltipField:'remark' }
]

export const downColumn = [
  ...commonColumn,
  { headerName: "报警ID", field: "alarmId", minWidth: 70, flex: 1, filter: 'agMultiColumnFilter' },
  { headerName: "发报警时间", field: "alarmSendTime", minWidth: 150, flex: 1, filter: 'agMultiColumnFilter' },
  { headerName: "读报警时间", field: "alarmReadTime", minWidth: 150, flex: 1, filter: 'agMultiColumnFilter' },
  { headerName: "消报警时间", field: "alarmEndTime", minWidth: 150, flex: 1, filter: 'agMultiColumnFilter' },
  { headerName: "报警文本", field: "alarmTxt", minWidth: 200, flex: 1, filter: 'agMultiColumnFilter', tooltipField:'alarmTxt' },
  { headerName: "读报警损失/分", field: "alarmReadDateTime", minWidth: 120, flex: 1, filter: 'agMultiColumnFilter' },
  { headerName: "消报警损失/分", field: "alarmLossDateTime", minWidth: 120, flex: 1, filter: 'agMultiColumnFilter' },

  { headerName: "报警等级", field: "alarmLevel", minWidth: 100, flex: 1, filter: 'agMultiColumnFilter' },
  { headerName: "报警部位", field: "alarmLocate", minWidth: 150, flex: 1, filter: 'agMultiColumnFilter', tooltipField:'alarmLocate' },
  { headerName: "损失计件", field: "lossCount", minWidth: 100, flex: 1, filter: 'agMultiColumnFilter' },
  { headerName: "累计持续时长/分", field: "totalTime", minWidth: 120, flex: 1, filter: 'agMultiColumnFilter' },
  { headerName: "累计反映时长/分", field: "totalReactTime", minWidth: 120, flex: 1, filter: 'agMultiColumnFilter' },
  { headerName: "备注", field: "remark", minWidth: 400, flex: 1, tooltipField:'remark' }
]

commonColumn.forEach((item:any) => {
  item.filter = 'agMultiColumnFilter'
})
